<%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%>
<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c" %>
<%
String path = request.getContextPath();
%>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
<link rel="stylesheet" type="text/css" href="<%=path %>/static/css/css.css?1" />
<link rel="stylesheet" type="text/css" href="<%=path %>/static/jquery-ui/jquery-ui.min.css" />
<script type="text/javascript" src="<%=path %>/static/js/json2.js"></script>
<script type="text/javascript" src="<%=path %>/static/js/jquery.js"></script>
<script type="text/javascript" src="<%=path %>/static/jquery-ui/jquery-ui.min.js"></script>
<script type="text/javascript" src="<%=path %>/static/layer/layer.js"></script>
<script type="text/javascript" src="<%=path %>/static/utf8-jsp/ueditor.config.js"></script>
<script type="text/javascript" src="<%=path %>/static/utf8-jsp/ueditor.all.js"></script>
<script type="text/javascript" src="<%=path %>/static/js/gridview.js?v=1"></script>
<script type="text/javascript" src="<%=path %>/static/js/formview.js?v=1"></script>
<script type="text/javascript" src="<%=path %>/static/js/tool.js"></script>
<script type="text/javascript" src="<%=path %>/static/js/validate.js"></script>

<SCRIPT type="text/javascript">
$.ajaxSetup({
  async: false
  });
    <!--
    genDicJs(['008','012']);
    var formSetting = {
    		po:'QhTask',
    		title:"任务编辑",
    		formid:"formedit",
    		hiddens:["id","adver","createUser","createDateTime","modifyUser","modifyDateTime","state"],
    	fields:[
             [
                {tdwidth:100,title:"计划名称",type:"text",name:"title",width:758,datatype:"Require",msg:"请输入计划名称！",colspan:3}
             ],
             [
                {title:"投放日期",type:"text",name:"",width:758,datatype:"Require",msg:"请输入推广链接！",colspan:3}
             ],
             [
                {title:"投放时间",type:"text",name:"",width:758,datatype:"Require",msg:"请输入推广链接！",colspan:3}
             ],
             [
                {title:"推广链接",type:"text",name:"advLink",width:758,datatype:"Require",msg:"请输入推广链接！",colspan:3}
             ],
             [
                {title:"产品类型",dic:"012",type:"select",name:"type",width:154,datatype:"Require",msg:"请选择产品类型！",colspan:3}
             ],
             [
                {title:"每日预算",type:"text",name:"investAmount",width:150,datatype:"Money",msg:"请输入格式正确的每日预算！"}
             ],
             [
                {title:"投放位置",type:"text",name:"",width:150}
             ],
    		 [
    		    {title:"图标",type:"uploadimg",name:"picUrl",width:"100"}
    		 ],
    		 [
                {title:"广告文案",type:"text",name:"advCopy",width:150,colspan:3}
             ],
             [
                {title:"付费模式",type:"text",name:"",width:150}
             ],
             [
                {title:"广告出价",type:"text",name:"shareProfit",width:150}
             ],
             [
                {title:"分享方向",type:"select",name:"shareDirect",width:154,dic:"008",datatype:"Require",msg:"请选择分享方向！"}
             ],
             [
                {title:"排序",type:"int",name:"sort",width:150,datatype:"Number",msg:"请输入格式正确的排序！",colspan:3,value:0}
             ],
             [
                {title:"备注",type:"text",name:"note",width:758,colspan:3}
             ]
             ],
		toolbar:{align:'right',buttons:[
		                 			  {
		                 			    	 id:'save',
		                 			    	 title:'保存',
		                 			    	 handlers:{
		                 			    		 click: function(){
		                 			    			 if(!Validator.Validate(document.getElementById('formedit'),0)){
		                 			    			    return;
		                 			    			 }
		                 			    			 var investAmount=$("input[name=investAmount]").val();
		                 			    			 if(investAmount==0){
		                 			    			     layer.msg("投放金额不能为0！");
		                 			    			     return;
		                 			    			 }
		                 			    			 $.getJSON(g_path+"/public/common/chkAvailFundByTask.htmls",{adver:$("input[name=adver]").val(),investAmount:investAmount},function(data){
                                                         if(data.state==1){
                                                             form.save(function(ret) {
                                                                 if (ret == -1) {
                                                                     layer.alert("数据保存失败，请重试！");
                                                                 } else {
                                                                     layer.msg("数据已保存！");
                                                                 }
                                                             });
                                                         }
                                                         else{
                                                             layer.msg("投放金额不能大于账户余额！");
                                                         }
                                                     });
		                 			    		 }
		                 			    	 }
		                 			     }
		                 			 ]}
    }

	var form;
    $(document).ready(function(){
    	form = new FormView("formview",formSetting);
    	form.init();

    	if('${sessionScope.userInfo.type}'=="B"){
    	    $("tr[rowindex=5]").hide();
    	    $("input[name=adver]").val('${sessionScope.userInfo.id}');
    	    $("input[name=adverName]").removeAttr("datatype");
    	}

    	var id='${param.id}';
    	if(id!=null&&id!=""){
    	   form.loadData(id, "QhTask");
    	}

		ajustHeight();
    });

    var $$ = function(func){
        if (document.addEventListener) {
            window.addEventListener("load", func, false);
        }
        else if (document.attachEvent) {
            window.attachEvent("onload", func);
        }
    }
    $$(function(){
        $("input[name=adverName]").click(function(){
                    layer.open({
                      	title : "选择广告主",
                      	type : 1,
                      	skin : 'layui-layer-rim', // 加上边框
                      	area : [ '450px', '380px' ], // 宽高
                      	content : $("#alertBox_user"),
                      	btn : [ "确认","关闭" ],
                      	yes : function(index, layero) {
                      	    $("input[name=adverName]").val($("input[name='rdoUser']:checked").next().text());
                      	    $("input[name=adver]").val($("input[name='rdoUser']:checked").val());
                            layer.close(index);
                      	},
                      	end : function(ret) {
                        }
                    });
        });

        $.getJSON(g_path+"/public/common/getAdverName.htmls",{uid:$("input[name=adver]").val()},function(data){
            $("input[name=adverName]").val(data.name);
        });

    });
    //-->
</SCRIPT>
</head>

<body>
<div id="formview0" class="rbox1"></div>
<div id="formview" class="rbox1"></div>
<div id="list" class="rbox2"></div>
<div id="fmUploadImg" style="display:none">
    <form method="post" enctype="multipart/form-data" name="form1" id="form1">
        <table>
            <tr>
                <td style="padding:20px 0 0 20px;">
                    <input type="file" name="userfile" id="inputImg" />
                </td>
            </tr>
        </table>
    </form>
</div>
<div id="alertBox_user" style="display:none">
      <table class="ctable">
         <tr>
            <td><input type="text" id="txtName" placeholder="请输入姓名" /></td>
            <td>
               <input type="button" id="btnSearch" class="btn2" value="查询" />
            </td>
         </tr>
      </table>
      <div id="alertBox_user1"></div>
</div>
<script type="text/javascript" src="<%=path %>/static/js/underscore.js"></script>
<script type='text/javascript' src='<%=path %>/static/My97DatePicker/WdatePicker.js'></script>
<script type='text/javascript' src='<%=path %>/dwr/engine.js'></script>
<script type='text/javascript' src='<%=path %>/dwr/util.js'></script>
<script type='text/javascript' src='<%=path %>/dwr/interface/BaseDwr.js'></script>
<script>
   $(function(){
      loadData();
      $("#btnSearch").click(function(){
         loadData();
      });
   });
   function loadData(){
      $.getJSON(g_path+"/public/common/getAdver.htmls",{name:$("#txtName").val()},function(data){
         var html="<ul class='selUser_ul' id='selUser_ul'>";

         $.each(data,function(i,item){
            html+="<li><input type='radio' id='rdoUser"+i+"' name='rdoUser' value='"+item.id+"' /><label for='rdoUser"+i+"'>"+item.name+"</label></li>";
         });
         html+="</ul>";
         $("#alertBox_user1").html(html);
      });
   }
</script>
</body>
</html>